package com.salefinder.client;

import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Image;

public class SearchResultWidget extends LayoutContainer {

//	public ConsumerProduct product;
	
	public SearchResultWidget(){
//		product = prod;
	}
	
	@Override
	protected void onRender(Element parent, int index) { 
		super.onRender(parent, index);
		this.setLayout(new FitLayout());
		
		ContentPanel cp = new ContentPanel();
		cp.setBodyBorder(true);  
		cp.setHeading("Grocery-> Milk -> Neilson");  
		cp.setLayout(new FitLayout());  
		cp.setFrame(false);  
		cp.setSize(700, 150);
		cp.setCollapsible(true);
					
		FlexTable table = new FlexTable();
		table.setWidth("100%");
		
		//TODO update the image file path
		Image img = new Image("drafts.gif");
		
		table.setWidget(0, 0, img);
		table.setWidget(4, 0, new Button("Add to list"));
		table.getFlexCellFormatter().setRowSpan(0,0, 4);
		
//		table.setWidget(0, 1, new Label("<b>Name</b>: Product 1"));
//		table.setWidget(0, 2, new Label("Category: Grocery"));
//		table.setWidget(0, 3, new Label("Brand: J&J"));
		
		table.setWidget(0, 1, new Label("Merchant: Walmart"));
		table.setWidget(0, 2, new Label("Price: $10"));
		
		table.setWidget(1, 0, new Label("Quantity: 1 liters"));
		table.setWidget(1, 1, new Label("Sale Price: $5"));
		
		table.setWidget(2, 0, new Label("Location: Woodbridge"));
		table.getFlexCellFormatter().setColSpan(2, 0, 2);
		
		table.setWidget(3, 0, new Label("Expires at: Jan 26, 2011"));
		table.getFlexCellFormatter().setColSpan(3, 0, 2);
		
		table.setWidget(4, 1, new Label("Description: 1 liters pck of milk"));
		table.getFlexCellFormatter().setColSpan(4, 1, 2);
		table.setStyleName("myresults");
		
		for(int i = 0; i < table.getRowCount(); i++){
			for(int j = 0; j < table.getCellCount(i); j++){
				table.getFlexCellFormatter().setStyleName(i, j, "myresultCell");
			}
		}
		
		cp.add(table);
		
		this.add(cp);
	}

}
